// 51021 patriking 1037 Accepted 504 kb 48 ms C++ 1379 B 2010-10-22 21:08:28 
#include<stdio.h>
#include<string.h>
const int maxn = 101;
int f[maxn][maxn];
int n;
int cnt_b;
int b_cnt;
int flag[maxn];

void dfs_b(int v)
{
	flag[v] = 1;
	for(int i = 1; i <= n; i++)
		if(flag[i]==0 && f[v][i] == 1){
			cnt_b++;
			dfs_b(i);
		}
}
void b_dfs(int v)
{
	flag[v] = 1;
	for(int i = 1; i <= n; i++)
		if(flag[i] == 0 && f[i][v] == 1){
			b_cnt++;
			b_dfs(i);
		}
}

int main()
{
	int m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(f,0,sizeof(f));
		for(int i = 0; i < m; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			f[x][y] = 1;
		}
		int ans = 0;
		for(int i = 1; i <= n; i++)
		{
			cnt_b = 0;
			memset(flag,0,sizeof(flag));
			dfs_b(i);
			b_cnt = 0;
			memset(flag,0,sizeof(flag));
			b_dfs(i);
			if(cnt_b + b_cnt == n-1)ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

